home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / scm / slib / gambit.init < prev    next >
Text File  |  1999-04-19  |  9KB  |  292 lines

  1. ;;;"gambit.init" Initialization for SLIB for Gambit    -*-scheme-*-
  2. ;;; Author: Aubrey Jaffer
  3. ;;;
  4. ;;; This code is in the public domain.
  5.  
  6. ;;; Updated 1992 February 1 for Gambit v1.71 -- by Ken Dickey
  7. ;;; Date: Wed, 12 Jan 1994 15:03:12 -0500
  8. ;;; From: barnett@armadillo.urich.edu (Lewis Barnett)
  9. ;;; Relative pathnames for Slib in MacGambit
  10. ;;; Hacked yet again for Gambit v2.4, Jan 1997, by Mike Pope
  11.  
  12. (define (software-type) 'MACOS)        ; for MacGambit.
  13. (define (software-type) 'UNIX)        ; for Unix platforms.
  14.  
  15. (define (scheme-implementation-type) 'gambit)
  16.  
  17. ;;; (scheme-implementation-home-page) should return a (string) URL
  18. ;;; (Uniform Resource Locator) for this scheme implementation's home
  19. ;;; page; or false if there isn't one.
  20.  
  21. (define (scheme-implementation-home-page)
  22.   "http://www.iro.umontreal.ca/~gambit/index.html")
  23.  
  24. (define (scheme-implementation-version) "3.0")
  25. ;;; Jefferson R. Lowrey reports that in Gambit Version 3.0
  26. ;;; (argv) returns '("").
  27. (define argv
  28.   (if (equal? '("") (argv))        ;Fix only if it is broken.
  29.       (lambda () '("Lowrey HD:Development:MacGambit 3.0:Interpreter"))
  30.       argv))
  31.  
  32. ;;; (implementation-vicinity) should be defined to be the pathname of
  33. ;;; the directory where any auxillary files to your Scheme
  34. ;;; implementation reside.
  35.  
  36. (define implementation-vicinity
  37.   (case (software-type)
  38.     ((UNIX)    (lambda () "/usr/local/src/scheme/"))
  39.     ((VMS)    (lambda () "scheme$src:"))
  40.     ((MS-DOS)    (lambda () "C:\\scheme\\"))
  41.     ((WINDOWS)  (lambda () "c:/scheme/"))
  42.     ((MACOS)
  43.      (let ((arg0 (list-ref (argv) 0)))
  44.        (let loop ((i (- (string-length arg0) 1)))
  45.      (cond ((negative? i) "")
  46.            ((char=? #\: (string-ref arg0 i))
  47.         (set! arg0 (substring arg0 0 (+ i 1)))
  48.         (lambda () arg0))
  49.            (else (loop (- i 1)))))))))
  50.  
  51. ;;; (library-vicinity) should be defined to be the pathname of the
  52. ;;; directory where files of Scheme library functions reside.
  53.  
  54. ;;; This assumes that the slib files are in a folder
  55. ;;; called slib in the same directory as the MacGambit Interpreter.
  56.  
  57. (define library-vicinity
  58.   (let ((library-path
  59.      (case (software-type)
  60.        ((UNIX) "/usr/local/lib/slib/")
  61.        ((MACOS) (string-append (implementation-vicinity) "slib:"))
  62.        ((AMIGA)    "dh0:scm/Library/")
  63.        ((VMS) "lib$scheme:")
  64.        ((WINDOWS MS-DOS) "C:\\SLIB\\")
  65.        (else ""))))
  66.     (lambda () library-path)))
  67.  
  68. ;;; (home-vicinity) should return the vicinity of the user's HOME
  69. ;;; directory, the directory which typically contains files which
  70. ;;; customize a computer environment for a user.
  71.  
  72. (define (home-vicinity) #f)
  73.  
  74. ;;; *FEATURES* should be set to a list of symbols describing features
  75. ;;; of this implementation.  Suggestions for features are:
  76.  
  77. (define *features*
  78.       '(
  79.     source                ;can load scheme source files
  80.                     ;(slib:load-source "filename")
  81.     compiled            ;can load compiled files
  82.                     ;(slib:load-compiled "filename")
  83.     rev4-report            ;conforms to
  84. ;    rev3-report            ;conforms to
  85.     ieee-p1178            ;conforms to
  86.     sicp                ;runs code from Structure and
  87.                     ;Interpretation of Computer
  88.                     ;Programs by Abelson and Sussman.
  89.     rev4-optional-procedures    ;LIST-TAIL, STRING->LIST,
  90.                     ;LIST->STRING, STRING-COPY,
  91.                     ;STRING-FILL!, LIST->VECTOR,
  92.                     ;VECTOR->LIST, and VECTOR-FILL!
  93. ;    rev2-procedures            ;SUBSTRING-MOVE-LEFT!,
  94.                     ;SUBSTRING-MOVE-RIGHT!,
  95.                     ;SUBSTRING-FILL!,
  96.                     ;STRING-NULL?, APPEND!, 1+,
  97.                     ;-1+, <?, <=?, =?, >?, >=?
  98.     multiarg/and-            ;/ and - can take more than 2 args.
  99.     multiarg-apply            ;APPLY can take more than 2 args.
  100.     rationalize
  101.     delay                ;has DELAY and FORCE
  102.     with-file            ;has WITH-INPUT-FROM-FILE and
  103.                     ;WITH-OUTPUT-FROM-FILE
  104. ;    string-port            ;has CALL-WITH-INPUT-STRING and
  105.                     ;CALL-WITH-OUTPUT-STRING
  106.     transcript            ;TRANSCRIPT-ON and TRANSCRIPT-OFF
  107.     char-ready?
  108. ;    macro                ;has R4RS high level macros
  109.     defmacro            ;has Common Lisp DEFMACRO
  110. ;    record                ;has user defined data structures
  111. ;    values                ;proposed multiple values
  112. ;    dynamic-wind            ;proposed dynamic-wind
  113.     ieee-floating-point        ;conforms to
  114.     full-continuation        ;can return multiple times
  115. ;    object-hash            ;has OBJECT-HASH
  116.  
  117. ;    sort
  118. ;    queue                ;queues
  119.     pretty-print
  120. ;    object->string
  121. ;    format
  122.     trace                ;has macros: TRACE and UNTRACE
  123. ;    compiler            ;has (COMPILER)
  124. ;    ed                ;(ED) is editor
  125.     system                ;posix (system <string>)
  126. ;    getenv                ;posix (getenv <string>)
  127.     program-arguments        ;returns list of strings (argv)
  128. ;    Xwindows            ;X support
  129. ;    curses                ;screen management package
  130. ;    termcap                ;terminal description package
  131. ;    terminfo            ;sysV terminal description
  132. ;    current-time            ;returns time in seconds since 1/1/1970
  133.     ))
  134.  
  135. ;;; (OUTPUT-PORT-WIDTH <port>)
  136. (define (output-port-width . arg) 79)
  137.  
  138. ;;; (OUTPUT-PORT-HEIGHT <port>)
  139. (define (output-port-height . arg) 24)
  140.  
  141. ;;; (CURRENT-ERROR-PORT)
  142. (define current-error-port
  143.   (let ((port (current-output-port)))
  144.     (lambda () port)))
  145.  
  146. ;;; (TMPNAM) makes a temporary file name.
  147. (define tmpnam (let ((cntr 100))
  148.          (lambda () (set! cntr (+ 1 cntr))
  149.              (string-append "slib_" (number->string cntr)))))
  150.  
  151. ;;; Gambit supports SYSTEM as an "Unstable Addition"; Watch for changes.
  152. (define system ##shell-command)
  153.  
  154. ;;; (FILE-EXISTS? <string>)
  155. ;(define (file-exists? f) #f)
  156.  
  157. ;;; (DELETE-FILE <string>)
  158. (define (delete-file f) #f)
  159.  
  160. ;;; FORCE-OUTPUT flushes any pending output on optional arg output port
  161. ;;; use this definition if your system doesn't have such a procedure.
  162. (define force-output flush-output)
  163.  
  164. ;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
  165. ;;; port versions of CALL-WITH-*PUT-FILE.
  166.  
  167. ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
  168. ;;; be returned by CHAR->INTEGER.
  169. (define char-code-limit 256)
  170.  
  171. ;; MOST-POSITIVE-FIXNUM is used in modular.scm
  172. (define most-positive-fixnum #x1FFFFFFF) ; 3-bit tag for 68K
  173.  
  174. ;;; Return argument
  175. (define (identity x) x)
  176.  
  177. ;;; SLIB:EVAL is single argument eval using the top-level (user) environment.
  178. (define slib:eval eval)
  179.  
  180. ; Define program-arguments as argv
  181. (define program-arguments argv)
  182.  
  183. ;;; If your implementation provides R4RS macros:
  184. ;(define macro:eval slib:eval)
  185. ;(define macro:load load)
  186.  
  187. ; Set up defmacro in terms of gambit's define-macro
  188. (define-macro (defmacro name args . body)
  189.   `(define-macro (,name ,@args) ,@body))
  190.  
  191. (define *defmacros*
  192.   (list (cons 'defmacro
  193.           (lambda (name parms . body)
  194.         `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body))
  195.                      *defmacros*))))))
  196. (define (defmacro? m) (and (assq m *defmacros*) #t))
  197.  
  198. (define (macroexpand-1 e)
  199.   (if (pair? e) (let ((a (car e)))
  200.           (cond ((symbol? a) (set! a (assq a *defmacros*))
  201.                      (if a (apply (cdr a) (cdr e)) e))
  202.             (else e)))
  203.       e))
  204.  
  205. (define (macroexpand e)
  206.   (if (pair? e) (let ((a (car e)))
  207.           (cond ((symbol? a)
  208.              (set! a (assq a *defmacros*))
  209.              (if a (macroexpand (apply (cdr a) (cdr e))) e))
  210.             (else e)))
  211.       e))
  212.  
  213. (define gentemp
  214.   (let ((*gensym-counter* -1))
  215.     (lambda ()
  216.       (set! *gensym-counter* (+ *gensym-counter* 1))
  217.       (string->symbol
  218.        (string-append "slib:G" (number->string *gensym-counter*))))))
  219.  
  220. (define base:eval slib:eval)
  221. (define defmacro:eval base:eval)
  222.  
  223. (define (defmacro:load <pathname>)
  224.   (slib:eval-load <pathname> defmacro:eval))
  225.  
  226. (define (slib:eval-load <pathname> evl)
  227.   (if (not (file-exists? <pathname>))
  228.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  229.   (call-with-input-file <pathname>
  230.     (lambda (port)
  231.       (let ((old-load-pathname *load-pathname*))
  232.     (set! *load-pathname* <pathname>)
  233.     (do ((o (read port) (read port)))
  234.         ((eof-object? o))
  235.       (evl o))
  236.     (set! *load-pathname* old-load-pathname)))))
  237.  
  238. (define slib:warn
  239.   (lambda args
  240.     (let ((port (current-error-port)))
  241.       (display "Warn: " port)
  242.       (for-each (lambda (x) (display x port)) args))))
  243.  
  244. ;; define an error procedure for the library
  245. (define slib:error error)
  246.  
  247. ;; define these as appropriate for your system.
  248. (define slib:tab (integer->char 9))
  249. (define slib:form-feed (integer->char 12))
  250.  
  251. ;;; Support for older versions of Scheme.  Not enough code for its own file.
  252. (define (last-pair l) (if (pair? (cdr l)) (last-pair (cdr l)) l))
  253. (define t #t)
  254. (define nil #f)
  255.  
  256. ;;; Define these if your implementation's syntax can support it and if
  257. ;;; they are not already defined.
  258.  
  259. (define (1+ n) (+ n 1))
  260. (define (-1+ n) (- n 1))
  261. (define 1- -1+)
  262.  
  263. (define in-vicinity string-append)
  264.  
  265. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  266. ;;; return if exitting not supported.
  267. (define slib:exit (lambda args (exit)))
  268.  
  269. ;;; Here for backward compatability
  270. (define scheme-file-suffix
  271.   (let ((suffix (case (software-type)
  272.           ((NOSVE) "_scm")
  273.           (else ".scm"))))
  274.     (lambda () suffix)))
  275.  
  276. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  277. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  278.  
  279. (define slib:load-source load)
  280.  
  281. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  282. ;;; by compiling "foo.scm" if this implementation can compile files.
  283. ;;; See feature 'COMPILED.
  284.  
  285. (define slib:load-compiled load)
  286.  
  287. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  288.  
  289. (define slib:load slib:load-source)
  290.  
  291. (slib:load (in-vicinity (library-vicinity) "require"))
  292.